<?php namespace system\model;
use houdunwang\model\Model;
class Config extends Model{
	//数据表
	protected $table = "config";

	//允许填充字段
	protected $allowFill = ['*'];

	//禁止填充字段
	protected $denyFill = [ ];

	//自动验证
	protected $validate=[
		//['字段名','验证方法','提示信息',验证条件,验证时间]
	];

	//自动完成
	protected $auto=[
		//['字段名','处理方法','方法类型',验证条件,验证时机]
	];

	//自动过滤
    protected $filter=[
        //[表单字段名,过滤条件,处理时间]
    ];

	//时间操作,需要表中存在created_at,updated_at字段
	protected $timestamps=true;
    public function setConfig($post){
        $model=Config::find(1);
        if(!$model){
            $model=$this;
        }
        $model->system = json_encode($post,JSON_UNESCAPED_UNICODE);
        $model->save();
    }
    public function setWexinConfig($post)
    {
        $model = Config::find(1);
        if(!$model) {
            //说明数据表找不到id=1数据，执行添加
            //$model = $this;
            //这句话，相当于楼上这一句
            $model = new static();
        }
        $model->weixin = json_encode($post,JSON_UNESCAPED_UNICODE);
        $model->save();
    }

    public function setWexinxiaoxiConfig($post){
        $model=Config::find(1);
        if(!$model){
            $model=$this;
        }
        $model->weixinxiaoxi= json_encode($post,JSON_UNESCAPED_UNICODE);
        $model->save();
    }
}